#include "ComboData.h"
#include <QDebug>


ComboData::ComboData()
{
	int role = Qt::UserRole;
	//    QHash<int, QByteArray> roles;
	m_roleNames.insert(role++, "text");
//    m_roleNames.insert(role++, "val");
}

int ComboData::rowCount(const QModelIndex &parent) const
{
	return m_modeData.size();   
}

QVariant ComboData::data(const QModelIndex &index, int role) const
{
    qDebug()<<"role:"<<m_roleNames[role]<<" index:"<<role<<" 1:"<<m_modeData[index.row()].first<<" 2:"<<m_modeData[index.row()].second;
    if (role - Qt::UserRole == 0)
        return m_modeData[index.row()].first;
    else if (role - Qt::UserRole == 1)
        return m_modeData[index.row()].second;
    return QVariant();
}

QHash<int, QByteArray> ComboData::roleNames() const
{
	return m_roleNames;
}

void ComboData::AddData(QPair<QString,QString> pData)
{
    m_modeData.append(pData);
}

QString ComboData::get(int nIndex)
{
    if (nIndex < m_modeData.size())
        return m_modeData[nIndex].second;
    return "";
}

void ComboData::append(QString text, QString role)
{
    beginResetModel();
    m_modeData.push_front(QPair<QString,QString>(text,role));
    endResetModel();
}


ComboData::~ComboData()
{

}
